package com.wgworkshop.pems.entity.converter;

import com.wgworkshop.pems.common.enums.GenderEnum;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * 性别转换器。
 * Created by wlc on 2017/7/2.
 */
@Converter
public class GenderConverter implements AttributeConverter<GenderEnum, Character> {

    @Override
    public Character convertToDatabaseColumn(GenderEnum attribute) {
        if (attribute == null) {
            return null;
        }
        return attribute.getCode();
    }

    @Override
    public GenderEnum convertToEntityAttribute(Character dbData) {
        if (dbData == null) {
            return null;
        }
        return GenderEnum.fromCode(dbData);
    }
}
